home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume91 / utilitys / bmake_06 / part03 < prev   
Encoding:
Internet Message Format  |  1991-07-04  |  18.2 KB

  1. Path: news.larc.nasa.gov!amiga-request
  2. From: amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
  3. Subject: v91i125: bmake 0.6 - automate recompiling multiple source files, Part03/03
  4. Reply-To: ENG  BENNY <engb@ecf.toronto.edu>
  5. Newsgroups: comp.sources.amiga
  6. Message-ID: <comp.sources.amiga.v91i125@ab20.larc.nasa.gov>
  7. References: <comp.sources.amiga.v91i123@ab20.larc.nasa.gov>
  8. Date: 04 Jul 91 16:38:43 GMT
  9. Approved: tadguy@uunet.UU.NET (Tad Guy)
  10. X-Mail-Submissions-To: amiga@uunet.uu.net
  11. X-Post-Discussions-To: comp.sys.amiga.misc
  12.  
  13. Submitted-by: ENG  BENNY <engb@ecf.toronto.edu>
  14. Posting-number: Volume 91, Issue 125
  15. Archive-name: utilities/bmake-0.6/part03
  16.  
  17. #!/bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 3 (of 3)."
  24. # Contents:  bmake.doc
  25. # Wrapped by tadguy@ab20 on Thu Jul  4 12:38:41 1991
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'bmake.doc' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'bmake.doc'\"
  29. else
  30. echo shar: Extracting \"'bmake.doc'\" \(16057 characters\)
  31. sed "s/^X//" >'bmake.doc' <<'END_OF_FILE'
  32. X
  33. X                       Documentation For The Make Utility
  34. X                           Copyright (c) 1991 by Ben Eng
  35. X
  36. X
  37. XBen Eng
  38. X150 Beverley St. Apt #1L
  39. XToronto, Ontario
  40. XM5T 1Y6
  41. X
  42. Xben@contact.uucp
  43. XBIX: jetpen
  44. X
  45. X
  46. XOVERVIEW
  47. X
  48. XMake is a programming utility used to automate the process of recompiling
  49. Xmultiple interdependent source files into an output file, which is called
  50. Xthe goal.  The rules for making the goal are explicitly stated in an input
  51. Xfile called the Makefile, and implicitly determined from builtin inference
  52. Xrules.  Normally, the Makefile for a goal is written so that the only thing
  53. Xthat needs to be done to recompile newly modified source files is to run
  54. Xthe Make program.
  55. X
  56. X
  57. XMAKEFILE
  58. X
  59. XThe Makefile is a text file which is read by the Make program.  The
  60. XMakefile is written to define the rules for making a goal up to date.  A
  61. Xgoal file is up to date if it has a modification datestamp that is more
  62. Xrecent than all of its dependents, after all dependents are made up to date
  63. Xwith respect to their dependents.  This criterion for up to dateness is
  64. Xapplied recursively, such that the most deep nested dependent will be made
  65. Xbefore any target file that depends on it.
  66. X
  67. XHere is an example of a simple Makefile, that does not correspond to what
  68. Xwould normally be used:
  69. X
  70. X# comment1
  71. X# comment2
  72. X
  73. Xgoal: target.o ; command three
  74. X
  75. Xtarget.o: source.c header.h
  76. X    command one
  77. X    command two
  78. X
  79. X
  80. XIn a Makefile, any line beginning with a `#' character is considered to be
  81. Xa comment line.  Comment lines are ignored by the Make program.  Rules are
  82. Xdefined by a line that begins with one or more target filenames, followed
  83. Xby a colon, an optional list of dependent filenames, an optional semicolon
  84. Xand an optional command.  Subsequent lines that begin with a tab character
  85. Xare command lines associated with the rule; the next line that does not
  86. Xbegin with a tab character indicates the end of the current rule and the
  87. Xbeginning of a new rule.
  88. X
  89. XIn the above example, the Make program will read the Makefile and find the
  90. Xfirst target filename to be ``goal''.  It will then attempt to make
  91. X``goal'' up to date by first making its dependencies (namely, ``target.o'')
  92. Xup to date.  In order to make ``target.o'' up to date, Make requires a rule
  93. Xthat contains ``target.o'' as a target filename.  Such a rule exists in the
  94. Xexample Makefile with dependencies ``source.c'' and ``header.h'', which
  95. Xmust in turn be made before ``target.o'' can be made up to date.  Since
  96. X``source.c'' and ``header.h'' are not defined as targets in the Makefile,
  97. Xthe Make program must use builtin rules of inference to make those files up
  98. Xto date, or it must give up and report that is doesn't know how to make the
  99. Xtarget.  As it turns out, the source and header files are known by builtin
  100. Xrules of inference to require no further action to be made up to date, so
  101. Xthe Make program can continue to make ``target.o'' now that its
  102. Xdependencies have fulfilled their requirements.  In order to make
  103. X``target.o'' up to date, ``command one'' must be executed successfully, and
  104. Xthen ``command two'' must be executed successfully after that.  Finally, the 
  105. Xgoal can be made by executing the command line, ``command three'', and the
  106. XMake program will terminate.
  107. X
  108. X
  109. XDEPENDENCIES
  110. X
  111. XIf there are no dependencies for a target, and a target needs to be remade
  112. Xby the Make program, then the target is always remade.  A target with no
  113. Xdependencies will always have its commands executed when that target needs
  114. Xto be remade.
  115. X
  116. XAdditional dependencies can be added to a target defined in another rule by
  117. Xwriting a new rule which declares the additional dependencies.  Only one of
  118. Xthe rules may contain command lines, otherwise it is an error.
  119. X
  120. X
  121. XMACROS and VARIABLES
  122. X
  123. XVariables can contain macro definitions of multiple filenames or other
  124. Xtext.  They are useful for replacing multiple occurrences of the same body
  125. Xof text with references to a variable (macro expansion).  A variable is
  126. Xdefined in the Makefile with an assignment statement.  Only the last
  127. Xassignment of a variable is recognized, because the rules are processed
  128. Xafter the entire Makefile has been interpreted into internal rules by the
  129. XMake program.
  130. X
  131. XIn a makefile, the line:
  132. X
  133. Xmyvariable = source.c header.h
  134. X
  135. Xis used to assign the string ``source.c header.h'' to the variable
  136. Xnamed ``myvariable''.  In the following rule definition:
  137. X
  138. Xtarget.o: $(myvariable)
  139. X
  140. Xthe ``$(myvariable)'' reference is expanded into the string assigned to
  141. X``myvariable''.  If the macro expansion contains further references to
  142. Xother varaiables, then they are also recursively expanded until the
  143. Xresulting string is fully expanded.  Undefined macros are expanded to
  144. Xnothing (empty strings).  ``${myvariable}'' is equivalent to
  145. X``$(myvariable)''.  For single character variable names, the parentheses or
  146. Xbraces are not necessary to expand the macro; the single character may
  147. Ximmediately follow the `$'.
  148. X
  149. XAdditional text can be concatenated to the end of the value of an existing
  150. Xvariable by using the ``+='' operator, like this:
  151. X
  152. Xalpha = abc
  153. Xalpha += def
  154. X
  155. XThe result of ``$(alpha)'' is now ``abc def''.  Notice the space inserted
  156. Xat the point of concatenation.  This ensures that filenames are not split
  157. Xbetween different lines.
  158. X
  159. XIt is possible to define a variable which results in an infinitely
  160. Xrecursive macro expansion.  This is illegal, and it will result in an
  161. Xerror when that variable is referenced.
  162. X
  163. XA variable can be defined, such that its value is expanded immediately at
  164. Xthe time of assignment.  These are called simple variables, and they are
  165. Xassigned with the ``:='' operator.  Note that when a simple variable is
  166. Xassigned, any other references to variables will expand to their value as
  167. Xassigned above the line of the simple variable being assigned.  Here is an
  168. Xexample:
  169. X
  170. Xsimplevar := $(myvariable)
  171. X
  172. XThe only difference between an ordinary variable and a simple variable is
  173. Xthat the value of the simple variable is expanded only once during its
  174. Xassignment, whereas the value of an ordinary variable needs to be
  175. Xexpanded every time it is referenced.  Referencing a simple variable
  176. Xrequires only a simple substitution, whereas referencing an ordinary
  177. Xvariable requires a recursive macro expansion, which requires more work.
  178. X
  179. XVariables referenced in the target and dependencies of a rule are expanded
  180. Xduring the rule definition.  Variables referenced in each command line
  181. Xassociated with a rule are expanded when the command line is executed.
  182. X
  183. XBoth ``\$'' and ``$$'' expand to the character `$'.
  184. X
  185. X
  186. XAUTOMATIC VARIABLES
  187. X
  188. XThere are a set of variables that are automatically defined at runtime by
  189. Xthe Make program.
  190. X
  191. X$@ expands to: target filename
  192. X$* expands to: target filename without its suffix
  193. X$< expands to: the first dependent filename
  194. X$^ expands to: all dependents of target newer than target (not-implemented)
  195. X$% expands to: dependent member of the target archive (not-implemented)
  196. X$? expands to: all dependents of the target archive (not-implemented)
  197. X
  198. XThe value of automatic variables depends on where they are referenced.  An
  199. Xautomatic variable has a different value according to the objects of the
  200. Xrule to which it applies.  $@ does not expand in the target position.
  201. XAutomatic variables making reference to dependencies do not make sense when
  202. Xused in the place of a target name or dependency, so they will not be
  203. Xdefined when referenced in those situations; those variables will expand to
  204. Xtheir proper value in command lines.
  205. X
  206. X
  207. XCOMPLEX VARIABLE NAMES and MACRO EXPANSIONS
  208. X
  209. XRarely is it necessary to apply what is is discussed in this topic, but the
  210. Xinformation will be given for completeness.  Because of the recursive
  211. Xnature of the macro expansion algorithm, it is possible to construct
  212. Xvariables that act like arrays (or other complex data types) through the
  213. Xuse of variable names that themselves contain a nested macro expansion.
  214. XHere is an example of an obscure sort of Makefile that uses this technique:
  215. X
  216. XA1    = one.c
  217. XA2    = two.c
  218. X
  219. Xtarget.o: ${A$(B)}
  220. X    $(CC) -c $(CFLAGS) -o $@ $<
  221. X
  222. XDepending on whether the value of the variable `B' is set to `1' or `2',
  223. Xthe target file will depend on ``one.c'' or ``two.c''.
  224. X
  225. XAlthough there is no strict limit restricting the level to which macros can
  226. Xbe nested (in the variable name and its value), it is recommended that
  227. Xnested be kept to a minimum to conserve on memory consumption and stack
  228. Xusage.  Each level of nesting requires at least an additional 2K of memory.
  229. X
  230. XPlease note that the maximum length of a variable name is 256 characters.
  231. X
  232. X
  233. XFUNCTION CALLS
  234. X
  235. XFunction calls of the form $(function arguments) or ${function arguments}
  236. Xwill be processed differently than a normal macro expansion.  A function
  237. Xcall acts like a macro expansion in that it returns a string.  All spaces,
  238. Xexcept for the sequence of spaces before the first argument (after
  239. Xexpansion), are significant.
  240. X
  241. XPlease note that the maximum length of the string within the parentheses is
  242. X1024 characters.
  243. X
  244. X
  245. XSTRING FUNCTIONS  (see section 9.2 of the GNU Make manual)
  246. X
  247. X$(filter pattern,text)
  248. X
  249. X    A pattern is a word that optionally contains a single wildcard
  250. X    character `%'.  All words in ``text'' that do not match the
  251. X    ``pattern'' are removed, so that this function call returns only
  252. X    matching words.
  253. X
  254. X
  255. X$(filter-out pattern,text)
  256. X
  257. X    All words in ``text'' that match the ``pattern'' are removed, so
  258. X    that this function call returns only non-matching words.  The
  259. X    result is the complement of the result of $(filter).
  260. X
  261. X
  262. X$(findstring find,in)
  263. X
  264. X    if the ``in'' string contains the ``find'' string then the ``find''
  265. X    string is returned, otherwise the result is an empty string
  266. X
  267. X$(patsubst pattern,replacement,text)
  268. X
  269. X    Not implemented yet
  270. X
  271. X$(sort list)
  272. X
  273. X    Not implemented yet
  274. X
  275. X$(strip string)
  276. X
  277. X    strips leading and trailing whitespace from string, and replaces
  278. X    embedded sequences of spaces with a single space.
  279. X
  280. X$(subst from,to,text)
  281. X
  282. X    replaces all occurrences in ``text'' that match ``from'' with the
  283. X    suffix ``to''.  NOTE:  because this is done with a literal
  284. X    substitution, the length of ``from'' must be equal to the length
  285. X    of ``to''.  This limitation is incompatible with GNU Make.
  286. X
  287. X
  288. XFILENAME FUNCTIONS  (see section 9.3 of the GNU Make manual)
  289. X
  290. X$(dir names)
  291. X    Not implemented yet
  292. X
  293. X$(notdir names)
  294. X    Not implemented yet
  295. X
  296. X$(suffix names)
  297. X    Not implemented yet
  298. X
  299. X$(basename names)
  300. X
  301. X    Extracts all but the suffix of each path name in ``names''.  The
  302. X    suffix is the rightmost part of the name starting at the last
  303. X    `.' character.
  304. X    
  305. X$(addsuffix suffix,names)
  306. X
  307. X    The result is the list of names with ``suffix'' appended to each
  308. X    word of the list.
  309. X
  310. X$(addprefix prefix,names)
  311. X
  312. X    The result is the list of names with ``suffix'' prepended to each
  313. X    word of the list.
  314. X
  315. X$(join list1,list2)
  316. X    Not implemented yet
  317. X
  318. X$(word n,text)
  319. X
  320. X    Returns the nth word of ``text''.  The first word of text is numbered
  321. X    1, and the last word of text is numbered $(words text).
  322. X
  323. X$(words text)
  324. X
  325. X    Returns the number of words in ``text''.
  326. X
  327. X$(firstword names)
  328. X
  329. X    Returns the first word of ``names''.  The result is the same as
  330. X    $(word 1,names)
  331. X
  332. X$(wildcard pattern)
  333. X
  334. X    The ``pattern'' argument is an Amiga OS wildcard pattern.  The
  335. X    result is a list of files matching that pattern.
  336. X
  337. X    An example of a generic makefile that can be used to compile a
  338. X    program that depends only upon all of the .c files in the
  339. X    current directory follows:
  340. X
  341. X    SRCS := $(wildcard #?.c)
  342. X    OBJS := $(subst .c,.o,$(SRCS))
  343. X
  344. X    a.out:    $(OBJS)
  345. X        $(CC) -o $@ $(CFLAGS) $(OBJS)
  346. X
  347. X
  348. XSPECIAL FUNCTIONS
  349. X
  350. X$(foreach var,list,text)    (see section 9.4 of the GNU Make manual)
  351. X$(origin variable)    (see section 9.5 of the GNU Make manual)
  352. X$(shell command line)    (see section 9.6 of the GNU Make manual)
  353. X
  354. X    None of the above are implemented yet
  355. X
  356. X
  357. XSUFFIX RULES
  358. X
  359. XWhen no explicit rule is defined for a target, the Make program must use
  360. Xother means to determine how to make the target up to date.  Rules of
  361. Xinference are defined by suffix rules.  An example of a double suffix rule
  362. Xis:
  363. X
  364. X.c.o:
  365. X    $(CC) -c $(CFLAGS) -o $@ $<
  366. X.SUFFIXES: .c .o
  367. X
  368. XThe above suffix rule defines how to make any target with a filename ending
  369. Xin ``.o'' if there is a corresponding dependent filename that ends in
  370. X``.c''.  The commands associated with a suffix rule are executed if the
  371. Xdependent file is newer than the target file.
  372. X
  373. XA single suffix rule of the form:
  374. X
  375. X.Z:
  376. X    compress $*
  377. X.SUFFIXES: .Z
  378. X
  379. Xis the same as a double suffix rule, except that there is no dependency
  380. Xsuffix.  As a result, the automatic variable ``$<'' is not defined in the
  381. Xscope of a single suffix rule.  Since there are no dependencies, any target
  382. Xmatching a single suffix rule will always be remade; the commands will
  383. Xalways be executed.
  384. X
  385. XA suffix rule has no dependencies listed to the right of the colon.  If
  386. Xsuch dependencies exist, then the rule definition is not considered a
  387. Xsuffix rule.
  388. X
  389. X
  390. XCOMMAND LINES IN RULES
  391. X
  392. XCommand lines are executed in order of appearance if any dependency is
  393. Xnewer than the target.  The commands executed for a rule should do
  394. Xsomething that causes the modification date to be updated.
  395. X
  396. XThe Make program knows nothing about what the command lines mean or do.
  397. XThe command lines are simply passed to the shell for execution.  If
  398. Xexecuting the command line results in an error, then the Make program will
  399. Xterminate.
  400. X
  401. XSometimes it is desirable to ignore the error returned by a command,
  402. Xbecause failure to execute the command does not affect the successful
  403. Xcompletion of the Makefile.  If this is true then the error returned by a
  404. Xcommand can be ignored by preceding the command with a `-' character.  For
  405. Xexample:
  406. X
  407. Xclean:
  408. X    -delete #?.o
  409. X
  410. XNormally, each command is printed (echoed) before execution.  Echoing for
  411. Xeach command can be disabled by preceding it with a `@' character.  This
  412. Xdoes not affect its execution.  The `@' character does not redirect the
  413. Xstandard output of the program being executed.  Redirection must be
  414. Xstated explicitly.
  415. X
  416. X
  417. XBUILTIN RULES
  418. X
  419. XBy default, the Make program knows several suffix rules.  Here is a list of
  420. Xtheir definitions:
  421. X
  422. X.a:
  423. X.c:
  424. X.h:
  425. X.i:
  426. X.c.o:
  427. X    $(CC) -c $(CFLAGS) -o $@ $<
  428. X.a.o:
  429. X    $(AS) -c $(AFLAGS) -o $@ $<
  430. X.SUFFIXES: .i .h .a .c .o
  431. X
  432. XNotice that assembler and C language headers and source files have no
  433. Xdependencies and require no commands to be executed in order to make them
  434. Xup to date.  User defined rules should be added to the Makefile if that is
  435. Xnot the case.
  436. X
  437. X
  438. XUSER DEFINED BUILTIN RULES
  439. X
  440. XIf the user needs to supplement the internal builtin rules with addition
  441. Xsuffix rules and variable definitions, they can be declared in one of two
  442. Xfiles:  ``S:builtins.make'' or ``builtins.make''.  If they exist, these two
  443. Xfiles are read (in the order listed above) before the Makefile by the Make
  444. Xprogram.  All rules and variables in these files may be referenced (or
  445. Xoveriden) in the Makefile.
  446. X
  447. X
  448. XCONDITIONAL DIRECTIVES
  449. X
  450. XA conditional directive can be used to control which parts of a Makefile
  451. Xare executed, based upon the value assigned to certain variables.  The
  452. Xfamiliar
  453. X
  454. Xif condition
  455. X    ...true...
  456. Xelse
  457. X    ...false...
  458. Xendif
  459. X
  460. Xsyntax is used for this purpose, where ``...true...'' represents any number
  461. Xof lines which are executed if the condition is true, and ``...false...''
  462. Xrepresents any number of lines which are executed if the condition is
  463. Xfalse.  Each of the three conditional directives must appear as the first
  464. Xword on a line.  The ``else'' directive is optional.  The condition may be
  465. Xone of the following:
  466. X
  467. Xeq(arg1,arg2)    true if arg1 is exactly equal to arg2
  468. Xneq(arg1,arg2)    true if arg1 is not equal to arg2
  469. Xdef(variable)    true if variable is defined
  470. Xndef(variable)    true if variable is undefined
  471. X
  472. XNested conditionals are acceptable.  There is no way to perform logical AND
  473. Xand logical OR operations within the condition expression, so nested
  474. Xconditionals will have to be used instead to do the same job.  Each ``if''
  475. Xand ``else'' must have a matching ``endif'' directive associated with its
  476. Xconditional construct.
  477. X
  478. XPRAGMA DIRECTIVE
  479. X
  480. XAny command line arguments may be added to a line beginning in ``pragma''.
  481. XFor example,
  482. X
  483. Xpragma +m2048
  484. X
  485. Xwill set the maximum line length to at least 2048 bytes, if that parameter
  486. Xhas not already been set to a higher value.
  487. X
  488. END_OF_FILE
  489. if test 16057 -ne `wc -c <'bmake.doc'`; then
  490.     echo shar: \"'bmake.doc'\" unpacked with wrong size!
  491. fi
  492. # end of 'bmake.doc'
  493. fi
  494. echo shar: End of archive 3 \(of 3\).
  495. cp /dev/null ark3isdone
  496. MISSING=""
  497. for I in 1 2 3 ; do
  498.     if test ! -f ark${I}isdone ; then
  499.     MISSING="${MISSING} ${I}"
  500.     fi
  501. done
  502. if test "${MISSING}" = "" ; then
  503.     echo You have unpacked all 3 archives.
  504.     rm -f ark[1-9]isdone
  505. else
  506.     echo You still need to unpack the following archives:
  507.     echo "        " ${MISSING}
  508. fi
  509. ##  End of shell archive.
  510. exit 0
  511. -- 
  512. Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
  513. Mail comments to the moderator at <amiga-request@uunet.uu.net>.
  514. Post requests for sources, and general discussion to comp.sys.amiga.misc.
  515.